package com.ruoyi.lvlian.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.lvlian.domain.ProductCategory;
import com.ruoyi.lvlian.dto.ProductCategoryDto;
import com.ruoyi.lvlian.dto.ProductDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.lvlian.domain.Product;
import com.ruoyi.lvlian.service.IProductService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 产品分类Controller
 *
 * @author lvlian
 * @date 2025-04-23
 */
@Api(value = "参数-购买方入库货品-L4", tags = "购买方入库货品")
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {
    @Autowired
    private IProductService productService;

    /**
     * 查询产品分类列表
     */
//    @RequiresPermissions("lvlian:product:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductDto product) {
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);
    }



    /**
     * 获取产品分类详细信息
     */
//    @RequiresPermissions("lvlian:product:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(productService.selectProductById(id));
    }



//    @RequiresPermissions("lvlian:product:edit")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Product product) {
        return toAjax(productService.updateProduct(product));
    }

    /**
     * 删除产品分类
     */
//    @RequiresPermissions("lvlian:product:remove")
/*    @Log(title = "产品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(productService.deleteProductByIds(ids));
    }*/


    @PostMapping("/remove")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(productService.deleteProductByIds(ids));
//        return toAjax(productCategoryService.updateProductCategory(productCategory));
    }




    @GetMapping("/queryProductListByCategoryTree")
    @ApiOperation("根据产品分类查询产品")
    public TableDataInfo queryProductListByCategoryTree(ProductDto product) {
        startPage();
        List<Product> list = productService.queryProductListByCategoryTree(product);
        return getDataTable(list);
    }

    @ApiOperation("获取产品分类树以及末节点的产品用在莱回收的产品树上")
    @GetMapping("/queryTreeAndProductList")
    public AjaxResult getCategoryTree(ProductCategoryDto productCategory ) {
        List<ProductCategory> categoryTree = productService.queryTreeAndProductList(  productCategory);
        return success(categoryTree);
    }




}
